﻿using System;
using System.Runtime.Serialization;
using System.Linq.Expressions;

namespace ExpressionSerialization
{
  [DataContract]
  public class XTypeBinaryExpression : XExpression
  {

    [DataMember]
    public XExpression Expression { get; set; }

    public override void FromExpression(Expression source_)
    {
      base.FromExpression(source_);
      TypeBinaryExpression unexp = source_ as TypeBinaryExpression;
      Expression = XExpression.CreateFromExpression(unexp.Expression);
    }

    public override Expression ToExpression(Type dataContract_, System.Collections.Generic.List<ParameterExpression> parameters_)
    {
      return System.Linq.Expressions.Expression.TypeIs(Expression.ToExpression(dataContract_,parameters_), GetExpressionType(dataContract_));
    }
  }
}
